package work.jame.blog.configuration.mybatis;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * @author : Jame
 * @date : 2022-06-07 09:00
 **/
public class MybatisPlusCodeGenerator {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/blog",
                "root",
                "root")
                .globalConfig(builder -> builder.author("Jame")
                        .outputDir(System.getProperty("user.dir")+"\\src\\main\\java")
                        .commentDate("yyyy-MM-dd")
//                    .fileOverride()
                        .disableOpenDir())
                .packageConfig(builder -> builder.parent("work.jame")
                .moduleName("blog")
                .entity("pojo")
                .service("service")
                .controller("controller")
                .mapper("mapper")
                .xml("mapper")
                .pathInfo(Collections.singletonMap(OutputFile.mapperXml,
                        System.getProperty("user.dir")+"\\src\\main\\resources\\mapper")))
                .strategyConfig(builder ->{
                        builder.serviceBuilder()
                        .formatServiceFileName("%sService")
                        .formatServiceImplFileName("%sServiceImpl")
                        .entityBuilder()
                        .logicDeletePropertyName("deleted")
                        .logicDeleteColumnName("deleted")
                        .enableTableFieldAnnotation()
                        .controllerBuilder()
                        .formatFileName("%sController")
                        .mapperBuilder()
                        .formatMapperFileName("%sMapper")
                        .enableBaseColumnList()
                        .enableBaseResultMap()
                        .formatXmlFileName("%sMapper");
                })

                .templateEngine(new FreemarkerTemplateEngine())
                .execute();

    }
}
